package com.fqy.thread.ticket02;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * User: fqy
 * Date: 2021/8/31
 * Time: 12:05
 * Describe:  interface Lock
 */
public class Ticket {
    private Integer number=50;
//    new Lock();
//   Lock lock = new ReentrantLock();// List list =new ArrayList();
    Lock lock = new ReentrantLock();
    public void sale(){
        lock.lock();
        try {
            if (number>0){
                System.out.println(Thread.currentThread().getName()+"\t"+"卖出第: "+(number--)+"\t 还剩下: "+number);
            }
        } finally {
            lock.unlock();
        }
    }
}
